package zjut.raymond.common;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Raymond
 * @Description TODO
 * @date 2021/7/9-13:48
 */
public class CommonUtils {
    public static double getMean(Collection<Integer> collection) {
        double sum = 0.0d;
        for (Integer i : collection) {
            sum += i;
        }
        return sum / collection.size();
    }

    public static double getStdDev(Collection<Integer> collection) {
        if (collection.size() <= 1) return 0.0;
        double varianceSum = 0.0d;
        double mean = getMean(collection);
        for (Integer i : collection) {
            double s = i - mean;
            varianceSum += Math.pow(s, 2);
        }
        return Math.sqrt(varianceSum / (collection.size() - 1));
    }
}
